package com.gorkr;

import java.util.LinkedList;



public class L101 {
    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    private boolean result=true;
    private LinkedList<Integer> left = new LinkedList<>();
    private LinkedList<Integer> right = new LinkedList<>();

    public boolean isSymmetric(TreeNode root) {
        leftTraverse(root);
        rightTraverse(root);
        if(left.size()!=right.size()){
            return false;
        }
        while(!left.isEmpty()){
            if(left.pop()!=right.pop()){
                return false;
            }
        }
        return true;
    }
    // public void check(TreeNode root){
    //     if(root==null){
    //         return;
    //     }


    //     check(root.left);
    //     check(root.right);
    // }

    public void leftTraverse(TreeNode root){
        if(root==null){
            left.add(-999);
            return;
        }
        left.add(root.val);
        leftTraverse(root.left);
        leftTraverse(root.right);
    }

// 1,2,3,-,-,4,-,-,2,4,-,-,3,-,-
// 1,2,3,-,-,4,-,-,2,4,-,-,3,-,-

    public void rightTraverse(TreeNode root){
        if(root==null){
            right.add(-999);
            return;
        }
        right.add(root.val);
        rightTraverse(root.right);
        rightTraverse(root.left);
        System.out.println();
    }



}